package com.yun;

import com.yun.entity.Student;
import com.yun.mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Main {
    public static void main(String[] args) {
//        构架工厂
        String resource = "mybatis-config.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
//        获取对象
        SqlSession sql = sqlSessionFactory.openSession();
//        List<Student> list = sql.selectList("stu.selectAll");
//        System.out.println(list);
//        获取mapper文件
        StudentMapper mapper = sql.getMapper(StudentMapper.class);
        System.out.println(mapper);
        List<Student> list = mapper.selectAll();
        System.out.println(list);

    }
}